import apis from "../../http/api/apis"
export default {
    namespaced:true,
    state: {
        pageSize: 3,
        currentPage: 1,
        productsList: [],
        total: 0,
        pageCount: "",
        all:[]
        
    },
    mutations: {
         //获取所有产品数据
         getAllProducts(state,allproducts){
            state.productsList=allproducts.data;
            // state.pageCount=allproducts.pageCount;
            state.total = allproducts.total;
            // console.log(allproducts);
           },
        //改变每页显示几条数据
        getPageSize(state,newPageSize) {
            state.pageSize = newPageSize;
        },
        //改变当前第几页
        getcurrentPage(state, newcurrentPage) {
            state.currentPage = newcurrentPage;
        },
        getall(state,a){
            state.all = a;
         }
    },
    actions: {
        //获取保险产品数据
       async getProducts(context) {
            const data = await apis.productsManages.getProducts({
                pageSize: context.state.pageSize,
                currentPage: context.state.currentPage,
            });
        //    console.log(data);
                context.commit("getAllProducts", data.data.data)
                // console.log('-------',data.data.data);
            
        },
        //新增保险
       async addProducts(context,upProduct) {
          return  await apis.productsManages.addProducts(upProduct);
        },
       //删除保险数据
        async deleteProducts(context, _id) {
           console.log('2222',_id);
        return await apis.productsManages.deleteProducts(_id);         
        },
       //修改保险产品信息
       async modifyProducts(context,upProduct) {
           return await apis.productsManages.modifyProducts(upProduct);  
        },
       //获取全部商品
       async getProductsall(context){
        const data=   await apis.productsManages.getProductsall();
        context.commit('getall',data.data)
       }

    },

    modules: {
    }
  }
  